[Coding014] LeetCode 21

Merge Two Sorted Lists

Ben 2023/08/04

More coding records

Get the knowledge flowing and circulating! :)

目录

本题收获

归并排序思想

题目:21. Merge Two Sorted Lists

You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.

Return the head of the merged linked list.

Example 1:

img

Example 2:

Example 3:

Constraints:


代码

复杂度分析

O(max(m+n))

m: list1的长度;

n: list2的长度。